package org.dyndns.opendemogroup.optimizer.problems;

import java.util.Random;

/**
 * Implements the sub-question b of part 1, question 2 in assignment #2. It is
 * called FlatCone because that's my interpretation of the shape when plotting
 * it.
 */
public class FlatCone extends EvolutionStrategyBase
{

	public FlatCone ( )
	{
		// hardcoded to 2 parameters, by definition
		super ( 2 );
	}

	/**
	 * @see EvolutionStrategyBase#computeFitness(Random)
	 */
	@Override
	public double computeFitness ( Random randomSource )
	{
		double fitness = 0.0;
		final double x1 = values[0];
		final double x2 = values[1];
		fitness =
			21.5 + x1 * Math.sin ( 4 * Math.PI * x1 ) + x2
					* Math.sin ( 20 * Math.PI * x2 );
		return fitness;
	}

	/**
	 * @see EvolutionStrategyBase#determineParameterMaximums()
	 */
	@Override
	protected double[] determineParameterMaximums ( )
	{
		double[] result =
		{
			12.1, 5.8
		};
		return result;
	}

	/**
	 * @see EvolutionStrategyBase#determineParameterMinimums()
	 */
	@Override
	protected double[] determineParameterMinimums ( )
	{
		double[] result =
		{
			-3.0, 4.1
		};
		return result;
	}

	/**
	 * @see EvolutionStrategyBase#determineSigmaMaximums()
	 */
	@Override
	protected double[] determineSigmaMaximums ( )
	{
		double[] result =
		{
			0.1, 0.1
		};
		return result;
	}

	/**
	 * @see EvolutionStrategyBase#determineSigmaMinimums()
	 */
	@Override
	protected double[] determineSigmaMinimums ( )
	{
		double[] result =
		{
			-0.1, -0.1
		};
		return result;
	}

	/**
	 * @see EvolutionStrategyBase#isMaximizing()
	 */
	@Override
	public boolean isMaximizing ( )
	{
		return false;
	}

}
